package com.texaco.chapasFutbol.utilidades;

import org.andengine.entity.Entity;
import org.andengine.entity.IEntity;
import org.andengine.entity.primitive.Line;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.color.Color;

import android.util.FloatMath;

public class Circle {
	Entity entity;
	float pi = 3.141592f;

	public Circle(float x, float y, float ratio, int segments, VertexBufferObjectManager vertexBuffer){
		entity = new Entity(x, y);
		
		float step = (2*pi)/segments;
		for(int i = 0; i < segments; i++) {
			float x1 = ratio * FloatMath.cos(i*step);
			float y1 = ratio * FloatMath.sin(i*step);
			float x2 = ratio * FloatMath.cos((i+1)*step);
			float y2 = ratio * FloatMath.sin((i+1)*step);
			Line line = new Line(x1, y1, x2, y2, 1000000000*i, vertexBuffer);
//			line.setLineWidth(1000*i);
			line.setColor(Color.BLACK);
			entity.attachChild(line);
		}
	}
	
	public void change(float x, float y, float ratio){
		float step = (2*pi)/entity.getChildCount();
		entity.setPosition(x, y);
		for(int i = 0; i < entity.getChildCount(); i++){
			float x1 = ratio * FloatMath.cos(i*step);
			float y1 = ratio * FloatMath.sin(i*step);
			float x2 = ratio * FloatMath.cos((i+1)*step);
			float y2 = ratio * FloatMath.sin((i+1)*step);
			((Line)entity.getChildByIndex(i)).setPosition(x1, y1, x2, y2);
		}
	}
	
	public IEntity getEntity(){
		return this.entity;
	}
}